package main

import (
	"database/sql"
	"fmt"
	_ "github.com/go-sql-driver/mysql"
	"time"
)

const (
	USERNAME = "root"
	PASSWORD = "qwer123"
	NETWORK  = "tcp"
	SERVER   = "localhost"
	PORT     = 3306
	DATABASE = "goiris"
)

func main() {
	dsName := "root:qwer123@tcp(127.0.0.1:3306)/goiris?charset=utf8&parseTime=true&loc=Local"
	db, err := sql.Open("mysql", dsName)
	if err != nil {
		fmt.Println(err)
	}
	db.SetMaxIdleConns(2)                //最大空闲连接数
	db.SetMaxOpenConns(3)                //最大打开链接数
	db.SetConnMaxLifetime(7 * time.Hour) //最大空闲时间
	fmt.Println(db.Ping())
	fmt.Println(db.Query("select now()"))
	defer db.Close()
}
